package com.nercel.dsj.gksales.model;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.List;

/**
 * @author sunlin
 * @date 2018-10-30
 * @param <T>
 */
@Data
@ApiModel(value = "数据列表")
public class ListResult<T> {

    @ApiModelProperty(value = "总数")
    private Long total;

    @ApiModelProperty(value = "列表")
    private List<T> data;

    @SuppressWarnings("unchecked")
    public ListResult(PageInfo pageInfo) {
        data = pageInfo.getList();
        total = pageInfo.getTotal();
    }

    @SuppressWarnings("unchecked")
    public ListResult(Page<?> page) {
        data = (List<T>)page.getResult();
        total = page.getTotal();
    }

    public static ListResult fromPageInfo(PageInfo pageInfo) {
        return new ListResult<>(pageInfo);
    }

    public static ListResult fromPage(Page<?> page){
        return new ListResult<>(page);
    }


}
